//
//  ViewController.m
//  controlFun
//
//  Created by student on 16/2/18.
//  Copyright © 2016年 niit. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UIAlertViewDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - 触摸背景,关闭键盘

// Storyboard中需要把self.view改成UIControl类
// TouchDown事件拉出个方法来
- (IBAction)backTap:(id)sender
{
    // 两种方法都可以
    // 1. 当前视图结束编辑状态
    //    [self.view endEditing:YES];
    
    // 2. 文本框取消第一响应者
    [self.nameTextField resignFirstResponder];
    [self.phoneTextField resignFirstResponder];
    
}



- (IBAction)segementChanged:(UISegmentedControl *)sender
{
    //分段控件的主要属性和方法:
    //当前选中项 selectedSegmentIndex
    //titleForSegementAtIndex 得到某段的标题
    NSLog(@"选中了%@",[sender titleForSegmentAtIndex:sender.selectedSegmentIndex]);
    
    // 1 如果是点开关段
    // 显示开关，隐藏按钮
    // 2 如果是点按钮段
    // 相反
    
    if(sender.selectedSegmentIndex == 0)
    {
        self.leftSwitch.hidden = NO;
        self.rightSwitch.hidden = NO;
        self.dosomethingBtn.hidden = YES;
    }
    else
    {
        self.leftSwitch.hidden = YES;
        self.rightSwitch.hidden = YES;
        self.dosomethingBtn.hidden = NO;
    }
}

- (IBAction)switchChanged:(UISwitch *)sender
{
    BOOL open = sender.on;
    [self.leftSwitch setOn:open animated:YES];
    [self.rightSwitch setOn:open animated:NO];

}

- (IBAction)doSomethingBtnPressed:(id)sender
{


    
}

- (IBAction)sliderChanged:(UISlider *)sender
{
    int value = sender.value;
    
    self.sliderValueLable.text = [NSString stringWithFormat:@"%i",value];

}

- (IBAction)btnPressed:(UIButton *)sender
{
    UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"你确定吗？"                 // 标题
                                                       delegate:self                              // 代理人
                                              cancelButtonTitle:@"取消"                 // cancelButtong标题
                                         destructiveButtonTitle:@"是的，我确定"                     // destructionButton标题
                                              otherButtonTitles:nil];  // 其他按钮的标题
    [sheet showInView:self.view];
}


#pragma mark UIAlertVIewDelegate Method


-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

{
    NSLog(@"用户点了第几个按钮=%d,按钮的文字信息:%@",buttonIndex+1,[alertView buttonTitleAtIndex:buttonIndex]);
    NSLog(@"弹窗的信息:%@",alertView.title);
    
    if([alertView.title isEqualToString:@"是的,我确定"])
    {
        NSString *info = [NSString stringWithFormat:@"%@",@"某些事项执行了，一切搞定了"];
        
    }
}

- (IBAction)btn1Pressed:(id)sender
{
    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"某些事被执行了" message:@"一切正常了"
                                                      delegate:self
                                             cancelButtonTitle:@"欧，耶"otherButtonTitles:nil];
    
    
    [alertView show];


}


// 取消的时候
- (void)alertViewCancel:(UIAlertView *)alertView NS_DEPRECATED_IOS(2_0, 9_0);
{
    NSLog(@"%s",__FUNCTION__);
}

// 将要弹出的时候
- (void)willPresentAlertView:(UIAlertView *)alertView
{
    NSLog(@"%s",__FUNCTION__);
}

// 已经弹出
- (void)didPresentAlertView:(UIAlertView *)alertView
{
    NSLog(@"%s",__FUNCTION__);
}

// 将要消失
- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
{
    NSLog(@"%s",__FUNCTION__);
}

// 已经消失
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    NSLog(@"%s",__FUNCTION__);
}


#pragma mark - UIActionSheetDelegate Method 操作表的代理方法
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSLog(@"操作表的标题:%@",actionSheet.title);
    NSLog(@"用户选择了哪一个按钮:%i,%@",buttonIndex,[actionSheet buttonTitleAtIndex:buttonIndex]);
    
    if(buttonIndex == actionSheet.destructiveButtonIndex)
    {
        NSLog(@"用户点了destructiveBtn");
    }
    else if(buttonIndex == actionSheet.cancelButtonIndex)
    {
        NSLog(@"用户点了cancelBtn");
    }
}











// 练习:
// 1. 编写doSomething按钮的事件处理方法
//    1.1 点击按钮弹出操作表,见图10501B.png
//    1.2 编写提示框的代理方法,如果点的是"是的,我确定"项,则弹出消息框,见10501C.png
// 2. 纯代码方式实现本程序
//纯代码方式修改view为UIControl类对象 见给出的例子




@end
